package com.navi.loaddata.loadService.impl.Dcdata;

import com.navi.loaddata.core.etlException.ETLException;
import com.navi.loaddata.core.mesEntity.SpcDcdataEntity;
import com.navi.loaddata.core.oracleEntity.array.EtlArrayPdsGlassV;
import com.navi.loaddata.core.util.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * @author jay
 */
@Service
public class ProcessDcDataServiceARRAY {

    private static final Logger logger = LoggerFactory.getLogger(ProcessDcDataServiceARRAY.class);

//    public List<EtlArrayPdsGlassV> processDcData(List<SpcDcdataEntity> spcDcdataEntityList,int errorProcessSpcDcdata) throws ETLException {
//        List<EtlArrayPdsGlassV> etlArrayPdsGlassVList = new ArrayList<>();
//        for(int i=0;i<spcDcdataEntityList.size();i++){
//            EtlArrayPdsGlassV etlArrayPdsGlassV = new EtlArrayPdsGlassV();
//            try {
//                etlArrayPdsGlassV = processDcData(spcDcdataEntityList.get(i), errorProcessSpcDcdata);
//                etlArrayPdsGlassVList.add(etlArrayPdsGlassV);
//            }catch (Exception e){
//                logger.error(LoggerUtil.stackTraceToString(e));
//                throw new ETLException(e.getMessage());
//            }
//        }
//        return etlArrayPdsGlassVList;
//    }

    public EtlArrayPdsGlassV processDcData(SpcDcdataEntity d, int errorProcessSpcDcdata) throws ETLException {
        EtlArrayPdsGlassV etlArrayPdsGlassV = new EtlArrayPdsGlassV();
        try {
            etlArrayPdsGlassV.setStepId(d.getProcessoperationname());
            etlArrayPdsGlassV.setSubEquipId(d.getUnitname());
            etlArrayPdsGlassV.setGlassId(d.getMaterialname());
            etlArrayPdsGlassV.setGlassEndTime(d.getEventtime());
            etlArrayPdsGlassV.setProductId(d.getProductspecname());
            etlArrayPdsGlassV.setRouteId(d.getProcessflowname());
            etlArrayPdsGlassV.setLotId(d.getLotname());
            etlArrayPdsGlassV.setEquipId(d.getMachinename());
            etlArrayPdsGlassV.setRunMode(d.getRunmode());
            etlArrayPdsGlassV.setRecipeId(d.getRecipename());
            etlArrayPdsGlassV.setOperatorId(d.getEventuser());
            etlArrayPdsGlassV.setOwnerId(d.getOwnercode());
            etlArrayPdsGlassV.setMesLinkKry(d.getMeslinkkey());
        }catch (Exception e){
            logger.error(errorProcessSpcDcdata+":"+e.getMessage());
            logger.error(LoggerUtil.stackTraceToString(e));
            throw new ETLException(errorProcessSpcDcdata+":"+e.getMessage());
        }
//        etlArrayPdsGlassV.setTaShift(); todo
        return etlArrayPdsGlassV;
    }

}
